home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / reuse.lha / reuse / m2c / Lists.c < prev    next >
C/C++ Source or Header  |  1992-08-18  |  3KB  |  175 lines

  1. #include "SYSTEM_.h"
  2.  
  3. #ifndef DEFINITION_Memory
  4. #include "Memory.h"
  5. #endif
  6.  
  7. #ifndef DEFINITION_IO
  8. #include "IO.h"
  9. #endif
  10.  
  11. #ifndef DEFINITION_Lists
  12. #include "Lists.h"
  13. #endif
  14.  
  15.  
  16.  
  17.  
  18. void Lists_MakeList
  19. # ifdef __STDC__
  20. (Lists_tList *List)
  21. # else
  22. (List)
  23. Lists_tList *List;
  24. # endif
  25. {
  26.   List->FirstElmt = NIL;
  27.   List->LastElmt = NIL;
  28. }
  29.  
  30. void Lists_Insert
  31. # ifdef __STDC__
  32. (Lists_tList *List, Lists_tElmt Elmt)
  33. # else
  34. (List, Elmt)
  35. Lists_tList *List;
  36. Lists_tElmt Elmt;
  37. # endif
  38. {
  39.   Lists_tListElmtPtr ActElmt;
  40.  
  41.   ActElmt = (Lists_tListElmtPtr)Memory_Alloc((LONGINT)sizeof(Lists_tListElmt));
  42.   ActElmt->Succ = NIL;
  43.   ActElmt->Elmt = Elmt;
  44.   if (List->FirstElmt == NIL) {
  45.     List->LastElmt = ActElmt;
  46.   } else {
  47.     ActElmt->Succ = List->FirstElmt;
  48.   }
  49.   List->FirstElmt = ActElmt;
  50. }
  51.  
  52. void Lists_Append
  53. # ifdef __STDC__
  54. (Lists_tList *List, Lists_tElmt Elmt)
  55. # else
  56. (List, Elmt)
  57. Lists_tList *List;
  58. Lists_tElmt Elmt;
  59. # endif
  60. {
  61.   Lists_tListElmtPtr ActElmt;
  62.  
  63.   ActElmt = (Lists_tListElmtPtr)Memory_Alloc((LONGINT)sizeof(Lists_tListElmt));
  64.   ActElmt->Succ = NIL;
  65.   ActElmt->Elmt = Elmt;
  66.   if (List->FirstElmt == NIL) {
  67.     List->FirstElmt = ActElmt;
  68.   } else {
  69.     List->LastElmt->Succ = ActElmt;
  70.   }
  71.   List->LastElmt = ActElmt;
  72. }
  73.  
  74. Lists_tElmt Lists_Head
  75. # ifdef __STDC__
  76. (Lists_tList List)
  77. # else
  78. (List)
  79. Lists_tList List;
  80. # endif
  81. {
  82.   return List.FirstElmt->Elmt;
  83. }
  84.  
  85. void Lists_Tail
  86. # ifdef __STDC__
  87. (Lists_tList *List)
  88. # else
  89. (List)
  90. Lists_tList *List;
  91. # endif
  92. {
  93.   List->FirstElmt = List->FirstElmt->Succ;
  94. }
  95.  
  96. Lists_tElmt Lists_Last
  97. # ifdef __STDC__
  98. (Lists_tList List)
  99. # else
  100. (List)
  101. Lists_tList List;
  102. # endif
  103. {
  104.   return List.LastElmt->Elmt;
  105. }
  106.  
  107. void Lists_Front
  108. # ifdef __STDC__
  109. (Lists_tList *List)
  110. # else
  111. (List)
  112. Lists_tList *List;
  113. # endif
  114. {
  115. }
  116.  
  117. BOOLEAN Lists_IsEmpty
  118. # ifdef __STDC__
  119. (Lists_tList List)
  120. # else
  121. (List)
  122. Lists_tList List;
  123. # endif
  124. {
  125.   return List.FirstElmt == NIL;
  126. }
  127.  
  128. CARDINAL Lists_Length
  129. # ifdef __STDC__
  130. (Lists_tList List)
  131. # else
  132. (List)
  133. Lists_tList List;
  134. # endif
  135. {
  136.   CARDINAL n;
  137.  
  138.   n = 0;
  139.   while (List.FirstElmt != NIL) {
  140.     INC(n);
  141.     List.FirstElmt = List.FirstElmt->Succ;
  142.   }
  143.   return n;
  144. }
  145.  
  146. void Lists_WriteList
  147. # ifdef __STDC__
  148. (IO_tFile f, Lists_tList List, Lists_tProcOfFileAddress Proc)
  149. # else
  150. (f, List, Proc)
  151. IO_tFile f;
  152. Lists_tList List;
  153. Lists_tProcOfFileAddress Proc;
  154. # endif
  155. {
  156.   while (!Lists_IsEmpty(List)) {
  157.     (*Proc)(f, Lists_Head(List));
  158.     Lists_Tail(&List);
  159.   }
  160. }
  161.  
  162. void BEGIN_Lists()
  163. {
  164.   static BOOLEAN has_been_called = FALSE;
  165.  
  166.   if (!has_been_called) {
  167.     has_been_called = TRUE;
  168.  
  169.     BEGIN_IO();
  170.     BEGIN_Memory();
  171.     BEGIN_IO();
  172.  
  173.   }
  174. }
  175.